package org.grow.stable;

import org.grow.stable.security.domain.Permission;
import org.grow.stable.security.domain.Role;
import org.grow.stable.security.domain.User;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

@Component
public class RandomDomain {
    private Random random = new Random();
    @Resource
    private PasswordEncoder passwordEncoder;

    public static String[] names = {"张三","李四"
            ,"王五","赵六","郑七","小强","小明","小李"};

    public List<User> randomUser(){
       return Arrays.asList(names)
                .stream()
                .map(s->{
                    User user = new User();
                    user.setNickname(s+"nick");
                    user.setBatch(random.nextInt(3));
                   // System.out.println(passwordEncoder.encode("111"));
                    user.setPassword(passwordEncoder.encode(
                            "12345"));

                    user.setRoles(new ArrayList<Role>(3){{
                        add(Role.values()[random.nextInt(Role.values().length)]);
                    }});
                    user.setUsername(s);
                    return user;
                }).collect(Collectors.toList());
    }
    public static String[] paths={"/upload","/download","/chat"};
    public List<Permission> randomPermission(){
        return Arrays.asList(paths)
                .stream()
                .map(s->{
                    Permission p = new Permission();
                    p.setDescription("hihi"+random.nextInt(100));
                    p.setPermissionId((random.nextInt(8999)+1000)+"_R");
                    p.setGroupIndex(1);
                    p.setPath(s);
                    p.setName(s);
                    p.setResourceType(Permission.ResourceType.MENU);
                    p.setRoles(new ArrayList<Role>(3){{
                        add(Role.values()[random.nextInt(Role.values().length)]);
                    }});
                    return p;
                }).collect(Collectors.toList());
    }
}
